//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using OpenLS.Drawing;
using OpenLS.Spreadsheet.UI.Internals;

namespace OpenLS.Spreadsheet.UI
{
    class EnsureWhiteConverter: IMultiValueConverter
    {

        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            object value = values[0];
            if (value == null)
                return Brushes.White;
            if (value == DependencyProperty.UnsetValue)
                return Brushes.White;

            if (value is Fill)
            {

                Brush result = FillToBrushConverter.GetBrush((Fill)value, values[1] as ColorScheme);
                if (result == null)
                    result = Brushes.White;
                if (result is SolidColorBrush && ((SolidColorBrush)result).Color.A == 0)
                    return Brushes.White;
                return result;
            }
            throw new NotSupportedException();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
